package com.zjl.学习.第05章_作业控制.A_作业的启动;

import org.springframework.batch.core.*;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Properties;

@RestController
public class A3_Controller {
    @Autowired
    private JobLauncher jobLauncher;

    @Autowired
    private Job job005;

    @Autowired
    private JobExplorer jobExplorer;  //job 展示对象

    @GetMapping("/job/start")
    public ExitStatus start(String name) throws Exception {
        //启动job作业
        JobParameters jobParameters = new JobParametersBuilder(jobExplorer)
                .getNextJobParameters(job005)
                .addString("name", name)
                .toJobParameters();
        //启动job作业
        JobExecution jobExecution = jobLauncher.run(job005, jobParameters);//  这种执行需要参数增量器 如 .incrementer(new RunIdIncrementer())
//        JobExecution jobExecution = jobLauncher.run(job005, new JobParameters());
        return jobExecution.getExitStatus();
    }
}
